package com.aiyige.page.publish.selecttraingcard.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.publish.selecttraingcard.model.TraingCard;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2018/3/14.
 */

public class TraingCardAdapter extends BaseQuickAdapter<TraingCard, TraingCardAdapter.ViewHolder> {
    public TraingCardAdapter() {
        super(R.layout.select_traing_card_item, new LinkedList<TraingCard>());
    }

    @Override
    protected void convert(ViewHolder helper, TraingCard item) {
        helper.bindData(item);
    }


    public class ViewHolder extends BaseViewHolder {
        @BindView(R.id.cardTypeTv)
        TextView cardTypeTv;
        @BindView(R.id.cardTitleTv)
        TextView cardTitleTv;
        @BindView(R.id.selectIv)
        ImageView selectIv;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(TraingCard card) {
            switch (card.getType()) {
                case TraingCard.TYPE_COUNT_CARD:
                    cardTypeTv.setText(R.string.count_card);
                    break;
                case TraingCard.TYPE_PREPAID_CARD:
                    cardTypeTv.setText(R.string.prepaid_card);
                    break;
                case TraingCard.TYPE_TIME_CARD:
                    cardTypeTv.setText(R.string.time_card);
                    break;
            }
            if (card.isSelected()) {
                selectIv.setImageResource(R.drawable.interest_elect);
            } else {
                selectIv.setImageResource(R.drawable.interest_normal);
            }
            cardTitleTv.setText(card.getTitle());
        }
    }
}
